﻿using System;
using SharpSqlAnalyzer.nodes;
using SharpSqlAnalyzer.pp.processor.type.comm;
using SharpSqlAnalyzer.pp.utils;
using SharpSqlAnalyzer.stmt;
using SharpSqlAnalyzer.stmt.mssql;

namespace SharpSqlAnalyzer.pp.processor.type.rtn
{
	// Token: 0x02000232 RID: 562
	public class ReturnStmtProcessor : AbstractProcessor
	{
		// Token: 0x060012CE RID: 4814 RVA: 0x0031A9C0 File Offset: 0x00318BC0
		public override void process(TParseTreeNode nodeArg)
		{
			TMssqlReturn tmssqlReturn = nodeArg as TMssqlReturn;
			TSourceToken startToken = tmssqlReturn.startToken;
			if (startToken == null)
			{
				return;
			}
			int num = SourceTokenOperator.curColumnNumberVT(startToken);
			int length = num + this.Option.beStyleBlockIndentSize;
			if (tmssqlReturn.Subquery == null)
			{
				if (tmssqlReturn.Statements != null && tmssqlReturn.Statements.size() > 0)
				{
					TStatementList statements = tmssqlReturn.Statements;
					if (statements.get(0) is TSelectSqlStatement)
					{
						TSelectSqlStatement tselectSqlStatement = (TSelectSqlStatement)statements.get(0);
						TSourceToken startToken2 = tselectSqlStatement.startToken;
						TSourceToken endToken = tselectSqlStatement.endToken;
						if (startToken2 != null && startToken2.astext.Equals("(") && endToken != null && endToken.astext.Equals(")"))
						{
							SourceTokenOperator.addBefore(this.Option, startToken2, SourceTokenOperator.createReturnSourceToken());
							SourceTokenOperator.addBefore(this.Option, startToken2, SourceTokenOperator.createWhitespaceSourceToken(num));
							SourceTokenOperator.addAfter(this.Option, startToken2, SourceTokenOperator.createReturnSourceToken());
							SourceTokenOperator.addAfter(this.Option, startToken2, SourceTokenOperator.createWhitespaceSourceToken(length));
							SourceTokenOperator.addBefore(this.Option, endToken, SourceTokenOperator.createReturnSourceToken());
							SourceTokenOperator.addBefore(this.Option, endToken, SourceTokenOperator.createWhitespaceSourceToken(num));
						}
						ExpressionProcessor.processParenthesesNodeInSubQuery(this.Option, tselectSqlStatement, tselectSqlStatement.startToken, tselectSqlStatement.endToken);
					}
				}
				return;
			}
			TSourceToken startToken3 = tmssqlReturn.Subquery.startToken;
			if (startToken3 == null)
			{
				return;
			}
			SourceTokenOperator.addBefore(this.Option, startToken3, SourceTokenOperator.createReturnSourceToken());
			SourceTokenOperator.addBefore(this.Option, startToken3, SourceTokenOperator.createWhitespaceSourceToken(length));
			ExpressionProcessor.processParenthesesNodeInSubQuery(this.Option, tmssqlReturn.Subquery, tmssqlReturn.Subquery.startToken, tmssqlReturn.Subquery.endToken);
		}
	}
}
